package com.gxar.marketdelivery.interfaces.web.controller;

import com.gxar.marketdelivery.application.facade.DeliveryResSlotFacade;
import com.gxar.marketdelivery.interfaces.web.param.BaseIdParam;
import com.gxar.marketdelivery.interfaces.web.param.CreateDeliveryResSlotParam;
import com.gxar.marketdelivery.interfaces.web.param.LongIdsParam;
import com.gxar.marketdelivery.interfaces.web.param.QueryDeliveryResSlotParam;
import com.gxar.marketdelivery.interfaces.web.param.UpdateDeliveryResSlotParam;
import com.gxar.marketdelivery.interfaces.web.result.APIResult;
import com.gxar.marketdelivery.interfaces.web.result.CommonPageResult;
import com.gxar.marketdelivery.interfaces.web.result.DeliveryResSlotResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping("/api/v1/delivery/resSlot")
@RestController
@Api(tags = "资源位管理API文档")
public class DeliveryResSlotController {

    @Autowired
    protected DeliveryResSlotFacade deliveryResSlotFacade;

    @PostMapping("/read/getPageList")
    @ApiOperation(value = "分页获取资源位信息", response = APIResult.class)
    public APIResult<CommonPageResult<DeliveryResSlotResult>> getPageList(
            @ApiParam(value = "资源位分页查询参数") @RequestBody QueryDeliveryResSlotParam param) {
        return new APIResult<>(deliveryResSlotFacade.getPageList(param));
    }

    @PostMapping("/read/detail")
    @ApiOperation(value = "根据ID获取单个资源位详情信息", response = APIResult.class)
    public APIResult<DeliveryResSlotResult> getDetail(
            @ApiParam(value = "资源位详情参数") @RequestBody BaseIdParam param) {
        return new APIResult<>(deliveryResSlotFacade.getDetail(param));
    }

    @PostMapping("/read/multiGetPlanStaticSchema")
    @ApiOperation(value = "根据资源位id列表查询资源位对应的投放计划schema", response = APIResult.class)
    public APIResult<Map<Long, String>> multiGetPlanStaticSchema(
            @ApiParam(value = "资源位信息参数") @RequestBody LongIdsParam param) {
        return new APIResult<>(deliveryResSlotFacade.multiGetPlanStaticSchema(param));
    }

    @PostMapping("/write/create")
    @ApiOperation(value = "创建资源位信息", response = APIResult.class)
    public APIResult create(@ApiParam(value = "资源位信息参数") @RequestBody CreateDeliveryResSlotParam param) {
        deliveryResSlotFacade.create(param);
        return new APIResult();
    }

    @PostMapping("/write/update")
    @ApiOperation(value = "更新资源位信息", response = APIResult.class)
    public APIResult update(@ApiParam(value = "资源位信息参数") @RequestBody UpdateDeliveryResSlotParam param) {
        deliveryResSlotFacade.update(param);
        return new APIResult<>();
    }

    @PostMapping("/write/open")
    @ApiOperation(value = "开启资源位", response = APIResult.class)
    public APIResult open(@ApiParam(value = "资源位信息参数") @RequestBody BaseIdParam param) {
        deliveryResSlotFacade.open(param);
        return new APIResult<>();
    }

    @PostMapping("/write/close")
    @ApiOperation(value = "关闭资源位", response = APIResult.class)
    public APIResult close(@ApiParam(value = "资源位信息参数") @RequestBody BaseIdParam param) {
        deliveryResSlotFacade.close(param);
        return new APIResult<>();
    }
}
